<?php

namespace maoxuner\LaravelJsonRpc\Entities;

use Illuminate\Contracts\Support\Arrayable;

abstract class EntityObject implements Arrayable
{
    public function __construct(array $attributes = [])
    {
        foreach ($attributes as $key => $value) {
            if (property_exists($this, $key)) {
                $this->{$key} = $value;
            }
        }
    }

    abstract public static function validate(array $data): array;

    public static function load(array $data): static
    {
        $validated = static::validate($data);

        return new static($validated);
    }
}
